package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Author Yjr
 * @Date 2025/5/21 9:52
 */
@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 新增套餐
     * @param dto
     * @return
     */
    @ApiOperation("新增套餐")
    @PostMapping
    public Result addSetmeal(@RequestBody SetmealDTO dto){
        setmealService.addSetmeal(dto);

        return Result.success();
    }

    /**
     * 套餐分页条件查询
     * @param dto
     * @return
     */
    @ApiOperation("套餐分页条件查询")
    @GetMapping("/page")
    public Result pageSetmeal(SetmealPageQueryDTO dto){
        PageResult pageResult= setmealService.pageSetmeal(dto);

        return Result.success(pageResult);
    }

    /**
     * 删除套餐
     * @param ids
     * @return
     */
    @ApiOperation("删除套餐")
    @DeleteMapping
    public Result deleteSetmeal(@RequestParam List<Integer> ids){
        setmealService.deleteSetmeal(ids);

        return Result.success();
    }

    /**
     * 根据id查询套餐详细信息
     * @param id
     * @return
     */
    @ApiOperation("根据id查询套餐详细信息")
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        SetmealVO setmealVO= setmealService.findById(id);

        return Result.success(setmealVO);
    }

    /**
     * 修改套餐
     * @param setmealDTO
     * @return
     */
    @ApiOperation("修改套餐")
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.updateSetmeal(setmealDTO);

        return Result.success();
    }

    /**
     * 修改套餐状态
     * @param status
     * @param id
     * @return
     */
    @ApiOperation("修改套餐状态")
    @PostMapping("/status/{status}")
    public Result updateSetmealStatus(@PathVariable Integer status,@RequestParam Long id){
        setmealService.updateSetmealStatus(status,id);
        return Result.success();
    }


}
